package cn.wyu.test;

import cn.wyu.dao.UserDaoImpl;
import cn.wyu.util.JDBCUtil;

import java.sql.ResultSet;

public class jdbcTest1 {
    @org.junit.Test
    public void test3(){
        UserDaoImpl userDao = new UserDaoImpl();
        String name = "John";
        String password = "123";
        userDao.register(name,password);
    }
    public static void main(String[] args) {

        test1();
        String sql = "select *from ec_article where TYPE_CODE like ?;";
        //查找用executeQuery
        ResultSet resultSet = JDBCUtil.executeQuery(sql, "0001%");

        //遍历出数据
        try{
            while(resultSet.next()){
                //得到数据
                int id = resultSet.getInt("ID");
                System.out.println(id);

            }
        }catch (Exception e){
            e.printStackTrace();
        }


    }
    public static void test1(){
        //增删改都是用executeUpdate
        String sql = "INSERT INTO `trian_web`.`ec_article_type`(`CODE`, `NAME`, `REMARK`) VALUES (?,?,?);\n;";
        int i = JDBCUtil.executeUpdate(sql,"0019","测试类","测试增加");
        if(i>0){
            System.out.println("添加成功");

        }
        else{
            System.out.println("添加失败");
        }
    }

}
